//
//  Operation.m
//  Tables
//
//  Created by mathias Muller on 8/23/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "Operation.h"



@implementation Operation

@synthesize leftValue;
@synthesize rightValue;
@synthesize operator;
@synthesize result;

+(Operation *) newOperation:(NSString*)op left:(NSInteger)l right:(NSInteger)r {
	Operation * instance = [[Operation  alloc] init];
	instance.operator = op;
	instance.leftValue = l;
	instance.rightValue = r;
	return instance;
}

- (NSString *) toString {
	return [NSString stringWithFormat:@"%i %@ %i",self.leftValue, self.operator, self.rightValue];  
}

- (BOOL)isCorrect {
	return result == [self getResult];
}

- (NSInteger)getResult {
	if([self.operator  isEqualToString: @"x"] ) {
		return self.leftValue * self.rightValue;
	} else if([self.operator  isEqualToString:@"-"]) {
		return self.leftValue - self.rightValue;
	} else if([self.operator  isEqualToString:@"+"]) {
		return self.leftValue + self.rightValue;
	} else if([self.operator  isEqualToString:@"/"] ) {
		return self.leftValue / self.rightValue;
	}
	return 0;
}

- (void)dealloc {
    [operator release];
    [super dealloc];
}
@end
